//
//  NSDictionary+null.m
//  pacc
//
//  Created by 测试 on 2018/6/21.
//  Copyright © 2018年 测试. All rights reserved.
//

#import "NSDictionary+null.h"
#import "NSArray+null.h"

@implementation NSDictionary (null)
- (NSDictionary *)dictionaryByReplacingNullsWithBlanks {
    
    const NSMutableDictionary *replaced = [self mutableCopy];
    
    const id nul = [NSNull null];
    
    const NSString *blank = @"";
    
    for (NSString *key in self) {
        
        id object = [self objectForKey:key];
        
        if (object == nul) [replaced setObject:blank forKey:key];
        
        else if ([object isKindOfClass:[NSDictionary class]]) [replaced setObject:[object dictionaryByReplacingNullsWithBlanks] forKey:key];
        
        else if ([object isKindOfClass:[NSArray class]]) [replaced setObject:[object arrayByReplacingNullsWithBlanks] forKey:key];
        
    }
    
    return [NSDictionary dictionaryWithDictionary:[replaced copy]];
    
}
- (NSDictionary *)deleteAllNullValue{
    
    NSMutableDictionary *mutableDic = [[NSMutableDictionary alloc] init];
    
    for (NSString *keyStr in self.allKeys) {
        
        if ([[self objectForKey:keyStr] isEqual:[NSNull null]]) {
            
            [mutableDic setObject:@"" forKey:keyStr];
            
        }
        
        else{
            
            [mutableDic setObject:[self objectForKey:keyStr] forKey:keyStr];
            
        }
        
    }
    
    return mutableDic;
    
}


//
@end
